import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
import java.util.Arrays;

/**
 * Created by mengwei666 on 2016/10/10.
 */

class Student {
    private String name;
    private long id;
    private int sumScore;
    public int[] array;

    public Student(String name, long id) {
        this.name = name;
        this.id = id;
        array = new int[5];
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setId(long id) {
        this.id = id;
    }

    public long getId() {
        return id;
    }

    public void setSumScore() {
        sumScore = 0;
        for (int i = 0; i < array.length; i++) {
            sumScore += array[i];
        }
    }

    public int getSumScore() {
        return sumScore;
    }
}
public class Main{
    //根据总成绩的快排函数
    static void quickSort(Student[] in, int begin, int end) {
        //begin为数组的第一个数据的索引值，end为数组的长度
        if( begin == end || begin == (end-1) ) return;         //若只有0或1个数据，直接返回
        Student p = in[begin];                          //p为参考数据
        int a = begin +1;                //a为分界线的索引值
        int b = a;
        for( ; b < end; b++) {
            if( in[b].getSumScore() < p.getSumScore()) {
                if(a == b){a++; continue;}
                Student temp = in[a];     //将数据左移
                in[a] = in[b];
                in[b] = temp;
                a++;           //分界线右移
            }
        }
        in[begin] = in[a-1];        //将参考值移动到两组数据中间
        in[a-1] = p;
        if( a-1 > begin){
            quickSort(in,begin, a);
        }
        if( end-1 > a ) {
            quickSort(in,a, end);
        }
        return;
    }
    public static void main(String[] args)  throws IOException{
        java.io.File gradesMenu=new java.io.File("src/GradesMenu.txt");
        java.io.File gradesList=new java.io.File("src/GradesList.txt");
        java.io.File studentList=new java.io.File("src/StudentList.txt");
        Random random=new Random();
        Scanner reader=new Scanner(gradesMenu);
        Scanner input=new Scanner(studentList);
        PrintWriter output=new java.io.PrintWriter(gradesList);
        int[] averageScore=new int[5];
        while(reader.hasNext()) {
            output.print(reader.next()+"    ");
        }
        output.println();
        List<Student> stuList=new ArrayList<Student>();
        while(input.hasNext()){
            Student student=new Student(input.next(),input.nextLong());
            for(int i=0;i<5;i++){
                student.array[i]=(int)(Math.sqrt(80)*random.nextGaussian()+75);
            }
            student.setSumScore();             //获取总成绩
            stuList.add(student);              //将学生对象添加到List上
            int _sumScore=0;
            for(int i=0;i<5;i++){
                averageScore[i]=0;
                //下面计算平均成绩
                for(int j=0;j<stuList.size();j++){
                    averageScore[i]+=stuList.get(j).array[i];
                }
                averageScore[i]/=5;
            }
        }
        Student[] in=new Student[stuList.size()];
        stuList.toArray(in);                     //将List<Student>转换为泛型数组，便于快排
        quickSort(in,0,stuList.size());          //快排
        stuList=Arrays.asList(in);              //将快排后的泛型数组重新转换为List<Student>
        for(int i=stuList.size()-1;i>=0;i--){
            output.print(stuList.get(i).getName()+"     ");
            output.print(stuList.get(i).getId()+"     ");
            for(int j=0;j<5;j++){
                output.print(stuList.get(i).array[j]+"      ");
            }
            output.println(stuList.get(i).getSumScore());
        }
        output.print("平均成绩            ");
        for(int i=0;i<5;i++) {
            output.print(averageScore[i] + "      ");
        }
        reader.close();
        output.close();
        input.close();
    }
}
